<template>
<div>
  <div class='list'>
    <h3>
      评论
      <span>共{{ commentCount }}条评论</span>
    </h3>
  </div>
  <div class='comments'>
    <div class='userimg'>
      <img v-if='!this.$store.state.user.show' width='50' height='50'
           src='http://s4.music.126.net/style/web2/img/default/default_avatar.jpg?param=50y50' alt=''>
      <img v-else width='50' height='50'
           :src='this.$store.state.user.avatarUrl' alt=''>
    </div>
    <div class='input'>
      <textarea  placeholder='评论' name='' id='' value='评论' cols='30' rows='10'></textarea>
      <div class='inputicon'>
        <div>
          <a href=''></a>
          <a href=''></a>
        </div>
        <button>评论</button>
      </div>
    </div>
  </div>
  <div class='usercommts'>
    <div class='goodcommts'>
      <h4>最新评论</h4>
    </div>

    <ul class='userhot'>
      <li v-for='(item,index) in hotuser'>
        <div class='comm-left'>
          <router-link  :to="'/user/' + item.user.userId">
            <img width='50' height='50' :src='item.user.avatarUrl' alt=''>
          </router-link>
        </div>
        <div class='comm-right'>
          <div class='comm-righttop'>
            <router-link :to="'/user/' + item.user.userId">
              <a style='color: #0c73c2; margin-right:0.5rem' href=''>{{ item.user.nickname }}:</a>
            </router-link>
            <span>{{ item.content }}</span>
          </div>
          <div class='comm-bottommsg'>
            <div class='usertime' style='color: #999'>
              {{ usertime[index] }}
            </div>
            <div class='userset'>
              <a href=''></a>
              <span v-if='item.likedCount !==0'>({{ item.likedCount }})</span>
              <b>|</b>
              回复
            </div>
          </div>
        </div>
      </li>
    </ul>

  </div>
  <div style='margin-top: 20px' class='usercommts'>
    <div class='goodcommts'>
      <h4>最新评论</h4>
    </div>
    <ul class='userhot'>
      <li v-for='(item,index) in newhotcomm'>
        <div class='comm-left'>
          <router-link  :to="'/user/' + item.user.userId">
            <img width='50' height='50' :src='item.user.avatarUrl' alt=''>
          </router-link>
        </div>
        <div class='comm-right'>
          <div class='comm-righttop'>
            <router-link :to="'/user/' + item.user.userId">
              <a style='color: #0c73c2;' href=''>{{ item.user.nickname }}:</a>
            </router-link>
            <span>{{ item.content }}</span>
          </div>
          <div class='comm-bottommsg'>
            <div class='usertime' style='color: #999'>
              {{ newtime[index] }}
            </div>
            <div class='userset'>
              <a href=''></a>
              <span v-if='item.likedCount !==0'>({{ item.likedCount }})</span>
              <b>|</b>
              回复
            </div>
          </div>
        </div>
      </li>
    </ul>

  </div>
</div>
</template>

<script>
import config from '@/network/config'
import axios from 'axios'
import moment from 'moment'

export default {
  name: 'Comment',
  props:['commentCount'],
  data() {
    return {
      url: config.url,
      //最热评论
      hotuser: [],
      usertime: [],
      comments:[],

      //最新评论
      newhotcomm:[],
      newuser:[],
      newtime:[],
    }
  },
  methods: {


    commenton() {
      axios.get(`${this.url}/comment/mv?`, {
        params: {
          id: this.$route.params.id
        }
      }).then(res => {
        var list = []

        this.newhotcomm = res.data.comments  //最新评论
        this.hotuser = res.data.hotComments  //最热评论

        //最热评论的时间
        res.data.comments.forEach(item => {
          list.push(item.time)
        })
        for (let i = 0; i < list.length; i++) {
          this.usertime.push((moment(list[i]).format('YYYY-MM-DD HH:mm')))
        }

        //最新评论的时间
        var time =  res.data.hotComments
        time.forEach(item => {
          list.push(item.time)
        })
        for (let i = 0; i < list.length; i++) {
          this.newtime.push((moment(list[i]).format('YYYY-MM-DD HH:mm')))
        }
      })
    },    //获取评论


  },
  mounted(){
    this.commenton()
  }


}

</script>

<style scoped>
.list {
  display: flex;
  margin-top: 50px;
  align-items: center;
  height: 33px;
  border-bottom: 2px solid #c20c0c;
  justify-content: space-between;
  margin-right: 30px;
  margin-bottom: 20px;
}
.left li:last-child {
  border-bottom: none;
  margin-bottom: 10px;
}

.recontent a, span {
  text-wrap: normal;
}

.recontent span {
  color: #999;
  font-size: 12px;
}

.recontent a {
  color: #666;
}

.recontent {
  overflow: hidden;
  text-overflow: ellipsis;
}

.recontent > a {
  font-size: 14px;
  color: #000000;
  white-space: nowrap;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;

}

.recontent {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
}

.recommend .userimg {
  margin-top: 10px;
  margin-right: 10px;
}

.recommend ul li {
  display: flex;
}

.recommend {
  width: 200px;

}

.right .header {
  display: flex;
  flex-wrap: wrap;
  width: 200px;
  justify-content: space-evenly;
  margin-top: 10px;

}

.right .header li {
  width: 40px;
  height: 40px;
  padding-right: 10px;
  padding-top: 10px;
}

.right h3 {
  height: 23px;
  border-bottom: 1px solid #ccc;
  color: #333;
  font-size: 12px;
  font-weight: lighter;
  width: 200px;
  padding: 12px 0 12px 0;
  margin-bottom: 5px;
}

.right {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.userset a {
  color: #999;
  display: inline-block;
  width: 15px;
  height: 14px;
  margin-right: 10px;
  background: url("../../../assets/images/icon2.png") -150px 0;

}

.userset b {
  color: #999;
  margin: 0 5px;
}

.userset {
  position: absolute;
  right: 0;
  display: flex;
  bottom: 0;
  align-items: center;
}

.comm-bottommsg {
  display: flex;
  justify-content: space-between;
  position: relative;
}

.comm-right span {
  font-size: 12px;
}

.comm-right {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-left: 10px;
  width: 100%;
  overflow: hidden;
}

.userhot > li {
  display: flex;
  margin-top: 10px;
  border-bottom: 1px solid #cfcfcf;
  padding-bottom: 10px;
  font-size: 12px;
}

/*精彩评论*/
.usercommts {
  width: 650px;
}

.usercommts h4 {
  font-size: 12px;
  font-weight: lighter;
  height: 20px;
  border-bottom: 1px solid #cfcfcf;
}

/*精彩评论*/
.inputicon a:nth-child(1) {
  width: 18px;
  height: 18px;
  background-position: -40px -490px;
  margin-right: 10px;

}

.inputicon a:nth-child(2) {
  width: 18px;
  height: 18px;
  background-position: -60px -490px;
}

.inputicon a {
  display: block;
  background: url("../../../assets/images/icon.png");
  width: 18px;
}

.inputicon {
  height: 18px;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;

}

.inputicon button:hover {
  background-position: -84px -94px;
  color: #fff;
  text-decoration: none;
}

.inputicon button {
  background: url("../../../assets/images/button.png") -84px -64px;
  width: 46px;
  height: 25px;
  text-align: center;
  line-height: 25px;
  font-size: 12px;
  border: none;
  outline: none;
  color: white;
}

.inputicon > div {
  display: flex;
}

.comments textarea {
  resize: none;
  outline: none;
  width: 578px;
  height: 63px;
  border: 1px solid #ccc;
}

.comments {
  display: flex;
  position: relative;

}

/*品论部分*/
.userimg {
  margin-right: 20px;
}

/*用户头像*/
.left-footer .list {
  display: flex;
  align-items: center;
  height: 33px;
  border-bottom: 2px solid #c20c0c;
  justify-content: space-between;
  margin-right: 30px;
  margin-bottom: 20px;
}

.more a {
  margin-top: 10px;
  width: 120px;
  height: 30px;
  background-image: linear-gradient(
    90deg, #ff5a4c 0%, #ff1d12 100%);
  border-radius: 18px;
  line-height: 30px;
  font-size: 12px;
  color: #ffffff;
  text-align: center;
}

.more p {
  font-size: 13px;
  color: #333333;
}

.more {
  justify-content: center;
  align-items: center;
  display: flex;
  flex-direction: column;
  margin-top: 30px;
  margin-bottom: 30px;
}

/*更多内容*/
tbody tr:nth-child(odd) {
  background: #F7F7F7;
}

.songss {
  width: 100%;
  height: 30px !important;
  display: flex;
  align-items: center;
}

.songss a {
  display: block;
  white-space: nowrap;

}

td a:hover {
  text-decoration: underline;
}

td {
  overflow: hidden;
  height: 30px !important;
  white-space: nowrap;
}

/* 表格信息*/
table .first {
  width: 74px;
}

.table-left {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

td .table-play:hover {
  background-position: 0 -128px;
}

td .table-play {
  background: url("../../../assets/images/table.png") 0 -103px;
  width: 17px;
  height: 17px;
}

table td {
  padding: 6px 10px;
  line-height: 18px;
  text-align: left;
}

th > div {
  background: url("../../../assets/images/table.png") 0 -56px no-repeat;
  padding: 8px 10px;
  font-weight: normal;
  color: #666;
}

table .title {
  width: 237px;
}

table th {
  height: 38px;
  color: #666;
  font-size: 12px;
  text-align: left;
  background: url("../../../assets/images/table.png") 0 0;
}

.songtable table {
  width: 650px;
  border: 1px solid #d9d9d9;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 12px;
}

/*表格*/
.list span {
  font-size: 12px;
  color: #666666;
}

.list span a {
  font-size: 12px;
  color: #c20c0c;
}

.list h3 span {
  margin: 9px 0 0 5px;
  color: #666;
  font-size: .5rem;
}

.list h3 {
  font-size: 20px;
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  font-weight: normal;
}
</style>